<template>
	<view class="all">
		<u-popup :show="show" :round="10" mode="bottom" @close="close">
		        <view class="model">
					<view class="title">
						选择房间
					</view>
					<view class="content">
						<view class="roomNum">
							<view :class="changeLeftBackground === index ? 'btnBlue' : 'btnWhite'" 
							v-for="(item,index) in roomList" :key="index"
							 @click="btnChange(index,item)"
							 >
								{{item.institution_num}}
							</view>
						</view>
						<view class="btn" @click="closeModel(item)">
							<view :class="selsected===''?'btn1':'btn2' ">
								确认
							</view>
							
						</view>
					</view>
		        </view>
		</u-popup>
		<view class="bac">
			<view class="item">
				<view class="left">
					<image style="width: 60rpx;height: 60rpx;" src="@/static/img/my_order_btn_reserved.png" mode=""></image>
				</view>
				<view class="right">
					<view v-if="dataList.amount_paid==''"  class="line_1">
						已预约
					</view>
					<view v-else class="line_1">
						已订房
					</view>
					<view v-if="dataList.amount_paid==''" class="line_2">
						看房日期：{{dataList.visitDate}}
					</view>
					<view  v-else class="line_2">
						入住日期：{{dataList.start_date}}
					</view>
				</view>
			</view>
			<view class="detials">
				<view class="detial">
					<view class="left">
						<view class="line1">
							{{roomInfo.home_type}}
						</view>
						<view class="line2">
							{{roomInfo.home_detail}}
						</view>
					</view>
					<view class="right" @click="toDetial2(dataList.institution_type.id)">
						查看房型
					</view>
				</view>
			</view>
			
		</view>
		<view class="btns">
			<view class="btn"  @click="showModel()">
				同意入住
			</view>
		</view>
		<view class="orders">
			<view class="orderInfo">
				<view class="">
					订单信息
				</view>
				<view class="" v-if="dataList.amount_paid!=''">
					订单编号：{{dataList.order_no}}
				</view>
				<view class="" v-if="dataList.amount_paid!=''">
					下单时间：{{dataList.created_at}}
				</view>
				<view class="" v-if="dataList.amount_paid!=''">
					支付订金：{{dataList.amount_paid}}
				</view>
				<view class="" v-if="dataList.amount_paid!=''">
					入住时间：{{dataList.start_date}}-{{dataList.end_date}}
				</view>
				<view class="" v-if="dataList.amount_paid==''">
					预约时间：{{dataList.created_at}}
				</view>
				<view class="" v-if="dataList.amount_paid==''">
					看房时间：{{dataList.visitDate}}
				</view>
				<view class="">
					联系人：{{dataList.contacts}}
				</view>
				<view class="">
					身份证号码：{{dataList.contacts_card}}
				</view>
				<view class="">
					联系电话：{{dataList.order_phone}}
				</view>
				<view class="">
					备注：{{dataList.order_remark}}
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {getOrderDetail,homeTypeInfo,noDepositAgreed} from '@/utils/api.js'
	export default {
		data() {
			return {
				show:false,
				changeLeftBackground:'',
				selsected:'',
				dataList:{},
				roomInfo:{},
				homeTypeId:'',
				selectedRoom:'',
				selectedRoom2:'',
				orderId:'',
				roomList:[
					401,
					402,
					402,
					402,
					402,
					402,
					402,
					402,
				]
			};
		},
		onLoad(option) {
			console.log(option,'option');
			this.orderId=Number(option.orderId) 
			getOrderDetail(option).then(res=>{
				if(res.data.meta.status==200){
					this.dataList=res.data.data
					this.roomInfo=res.data.data.institution_type
					this.homeTypeId=res.data.data.institution_type.id
				}
			})
			
		},
		onShow() {
			
		},
		methods:{
			toDetial2(id){
				
				console.log(id,'ddd');
				uni.navigateTo({
					url:'/pages/room/roomDetial2?homeTypeId='+id
				})
			},
			showModel(){
				this.show=true
				let data ={homeTypeId:this.homeTypeId}
				homeTypeInfo(data).then(res=>{
					if(res.data.meta.status==200){
						this.roomList=res.data.data.home_num
						let newArr=[]
						this.roomList.forEach((item)=>{
							if(item.instutution_status==1){
								newArr.push(item)
							}
						})
						this.roomList=newArr
					}
				})
			},
			closeModel(item){
				if(this.selsected){
					console.log(this.selectedRoom);
					let data ={bookingId:this.orderId,roomID:this.selectedRoom}
					noDepositAgreed(data).then(res=>{
						if(res.data.meta.status==200){
							this.show=false
							uni.showToast({
								title:'已通知客户入住'+ this.selectedRoom2+',等待付款' ,
								icon:'none'
							})
							setTimeout(()=>{
								uni.switchTab({
									url:'/pages/order/order'
								})
							},1000)
							
						}
					})
					
				}
				else{
					console.log('xxx');
				}
				
			},
			close(){
				this.show=false
			},
			btnChange(index,item){
				console.log(item,'item');
				this.changeLeftBackground=index
				this.selectedRoom=item.id
				this.selsected=index+1
				this.selectedRoom2=item.institution_num
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.all{
		.model{
			.title{
				height: 110rpx;
				line-height: 110rpx;
				text-align: center;
				font-size: 32rpx;
				font-weight: bold;
				border-bottom: 2rpx solid #F6F6F6;
			}
			.content{
				.roomNum{
					padding: 40rpx 48rpx;
					display: flex;
					flex-wrap:wrap;
					.btnBlue{
						width:150rpx ;
						height: 64rpx;
						background: #5398F6;
						border-radius: 8rpx;
						text-align: center;
						line-height: 64rpx;
						font-size: 28rpx;
						font-weight: 500;
						color: #FFFFFF;
						margin-bottom: 20rpx;
						margin-right: 12rpx;
					}
					.btnWhite{
						width:150rpx ;
						height: 64rpx;
						background: #F6F6F6;
						border-radius: 8rpx;
						text-align: center;
						line-height: 64rpx;
						font-size: 28rpx;
						font-weight: 500;
						color: #484848;
						margin-bottom: 20rpx;
						margin-right: 12rpx;
					}
				}
				.btn{
					height: 150rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					.btn2{
						width: 462rpx;
						height: 88rpx;
						background: #5398F6;
						border-radius: 44rpx;
						font-size: 32rpx;
						font-weight: bold;
						color: #FEFEFE;
						text-align: center;
						line-height: 88rpx;
					}
					.btn1{
						width: 462rpx;
						height: 88rpx;
						background: #A8A8A8;
						border-radius: 44rpx;
						font-size: 32rpx;
						font-weight: bold;
						color: #FEFEFE;
						text-align: center;
						line-height: 88rpx;
					}
				}
			}
		}
		.bac{
			height: 256rpx;
			background: #5398F6;
			position: relative;
			.item{
				height: 100rpx;
				position: absolute;
				top: 20rpx;
				padding: 52rpx 0 0 48rpx;
				display: flex;
				width: 100%;
				.left{
					width: 60rpx;
					height: 60rpx;
					line-height: 80rpx;
				}
				.right{
					margin-left: 20rpx;
					margin-top: -20rpx;
					color: white;
					.line_1{
						font-size: 36rpx;
						font-weight: bold;
						color: #FFFFFF;
					}
					.line_2{
						font-size: 26rpx;
						font-weight: 500;
						color: #FFFFFF;
					}
				}
			}
			.detials{
				// padding: 0 24rpx 0 24rpx;
				height: 152rpx;
				width: 100%;
				position: absolute;
				bottom: -76rpx;
				.detial{
					margin: 0 24rpx;
					height: 152rpx;
					background: #FFFFFF;
					border-radius: 16rpx;
					display: flex;
					.left{
						width: 75%;
						margin-left: 24rpx;
						line-height: 45rpx;
						margin-top: 35rpx;
						.line1{
							font-size: 32rpx;
							font-weight: bold;
							color: #242424;
						}
						.line2{
							font-size: 24rpx;
							font-weight: bold;
							color: #686868;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}
					}
					.right{
						width: 25%;
						line-height:152rpx ;
						font-size: 24rpx;
						font-weight: bold;
						color: #5398F6;
						text-align: center;
					}
				}
			}
			
			
		}
		.btns{
			height: 300rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			.btn{
				width: 462rpx;
				height: 88rpx;
				background: #5398F6;
				border-radius: 44rpx;
				text-align: center;
				line-height: 88rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #FEFEFE;
				margin-top: 100rpx;
			}
		}
		.orders{
			padding: 0 24rpx;
			.orderInfo{
				border-radius: 16rpx;	
				background-color: #FFFFFF;	
				padding: 40rpx 24rpx;
			}
			.orderInfo :first-child{
				font-size: 36rpx;
				font-weight: bold;
				color: #242424;
			}
			.orderInfo :not(:first-child){
				font-size: 28rpx;
				font-weight: bold;
				color: #686868;
				line-height: 50rpx;
				margin-top: 20rpx;
			}
		}
		
	}
</style>
